package com.dule.Medic.beans;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.apache.tapestry5.beaneditor.NonVisual;

import com.dule.Medic.model.MedEntry;
import com.dule.Medic.model.Patient;
import com.dule.Medic.beans.MedEntryBean;
import java.util.*;

@SuppressWarnings("serial")
@Entity
@Table(name="patient")
public class PatientBean implements Patient,Serializable
{
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@NonVisual
	private Long id;
	
	@Basic
	private String medInsNo;
	@Basic
	private String firstName;
	@Basic
	private String lastName;
	@Basic
	private String adress;
	@Basic
	private String phone; 
	@Basic
	private String email; 
	
	@OneToMany(targetEntity=MedEntryBean.class) 
	private List<MedEntry> medEntries =new LinkedList<MedEntry>();

	
	public Long getId() 
	{
		return id;
	}
	public void setId(Long id) 
	{
		this.id = id;
	}
	public String getMedInsNo() {
		return medInsNo;
	}
	public void setMedInsNo(String medInsNo) {
		this.medInsNo = medInsNo;
	}
	public String getFirstName() {
		return firstName;
	}
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	public String getLastName() {
		return lastName;
	}
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	public String getAdress() {
		return adress;
	}
	public void setAdress(String adress) {
		this.adress = adress;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public List<MedEntry> getMedEntries() {
		return medEntries;
	}
	public void setMedEntries(List<MedEntry> medEntries) {
		this.medEntries = medEntries;
	}		
	public MedEntry getMedEntryById(Long id) 
	{
		for(MedEntry me:medEntries)
        {
			if(me.getId().equals(id))
			{
                return me;
			}
        }
        return null;
    }
	public boolean UpdateMedEntry(MedEntry medentry) 
	{
		for(MedEntry me:medEntries)
        {
			if(me.getId().equals(medentry.getId()))
			{
				medEntries.remove(me);
				medEntries.add(medentry);
				return true;
				
			}
        }
        return false;
    }
	public boolean RemoveMedEntry(MedEntry medentry) 
	{
		for(MedEntry me:getMedEntries())
        {
			if(me.getId().equals(medentry.getId()))
			{
				getMedEntries().remove(me);
				return true;
			}
        }
        return false;
    }
	
	public PatientBean() {
		// TODO Auto-generated constructor stub
	}
}
